package com.sgcc.nfc.lock.data.remote.dto

import com.google.gson.annotations.SerializedName
import com.sgcc.nfc.lock.domain.model.PagedList

data class PagedDataDto<T>(
    @SerializedName("size") val size: Long?,
    @SerializedName("records") val records: List<T>?,
    @SerializedName("current") val current: Long?,
    @SerializedName("total") val total: Long?,
    @SerializedName("pages") val pages: Long?
) {
    fun <R> map(transform: (T) -> R): PagedList<R> = PagedList(
        data = records?.map(transform).orEmpty(),
        page = current ?: 1L,
        pageSize = size ?: records?.size?.toLong() ?: 0L,
        total = total ?: 0L,
        pageCount = pages ?: 0L
    )
}
